<template>

  <div class="page-demand-detail">
    <div class="table w50">
      <div class="table-row-group" >
        <ul class="table-row">
          <li class="table-cell-title br0">状态</li>
          <li class="table-cell-content br0">{{formData.statusDesc}}</li>
          <li class="table-cell-title br0">求购人</li>
          <li class="table-cell-content">{{formData.contactName}}</li>
        </ul>
      </div>
      <div class="table-row-group" >
        <ul class="table-row">
          <li class="table-cell-title br0">手机号码</li>
          <li class="table-cell-content br0">{{formData.contactMobileNo}}</li>
          <li class="table-cell-title br0">公司</li>
          <li class="table-cell-content">{{formData.companyName}}</li>
        </ul>
      </div>
      <div class="table-row-group" >
        <ul class="table-row">
          <li class="table-cell-title br0">产品名称</li>
          <li class="table-cell-content br0">{{formData.goodsName}}</li>
          <li class="table-cell-title br0">产地</li>
          <li class="table-cell-content">{{formData.countryOrigin}}</li>
        </ul>
      </div>
      <div class="table-row-group" >
        <ul class="table-row">
          <li class="table-cell-title br0">意向价格（RMB/KG）</li>
          <li class="table-cell-content br0">{{formData.intentPriceString}}</li>
          <li class="table-cell-title br0">厂号</li>
          <li class="table-cell-content">{{formData.vendorNo}}</li>
        </ul>
      </div>
      <div class="table-row-group" >
        <ul class="table-row">
          <li class="table-cell-title br0">求购地</li>
          <li class="table-cell-content br0">{{formData.city}}</li>
          <li class="table-cell-title br0">求购量(吨)</li>
          <li class="table-cell-content">{{formData.weight}}</li>
        </ul>
      </div>
      <div class="table-row-group" >
        <ul class="table-row">
          <li class="table-cell-title br0">查看人数</li>
          <li class="table-cell-content br0">{{formData.seeCount}}</li>
          <li class="table-cell-title br0">报价人数</li>
          <li class="table-cell-content">{{formData.quoteCount}}</li>
        </ul>
      </div>
    </div>
    <div class="table mb-1">
      <div class="table-row-group" >
        <ul class="table-row">
          <li class="table-cell-title-lastrow">要求</li>
          <li class="table-cell-content-lastrow br0">{{formData.remarkDemand}}</li>
        </ul>
      </div>
    </div>
    <br><br>
    <edit-pic :headTitle="'请上传交易凭证'" :fileUrlsArray="this.imageFiles"
               :headSonTitle="'支持pdf,jpg,png,gif,bmp(最多选择10张)'"  @getFileUrls="getFileUrls"></edit-pic>
    <div class="remarkFrameClass">
      <div class="remarkTitleClass">
        <span>备注（选填）</span>
      </div>
      <div class="remarkContentClass">
        <el-input  type="textarea" v-model="remarkClose" :value="remarkClose" maxlength="300" :rows="4" placeholder="填写备注"></el-input>
      </div>
    </div>
    <el-row class="btnFrameClass">
      <el-button v-if="this.isClose" class="singleBtnClass" type="primary" @click="updateCredential">确定</el-button>
      <el-button v-if="!this.isClose" class="singleBtnClass" type="primary" @click="updateCredential">更新</el-button>
    </el-row>
  </div>

</template>
<script type="text/ecmascript-6">
  import PcDialog from 'components/dialog';
  import fileUpload from 'components/fileUpload/file.vue';
  import editPic from './editPicture.vue';
  import inputCom from 'components/input/baseTitleInput.vue';
  export default{
    props: {
      id: [String, Number],
      isCloseOper: [String, Boolean]
    },
    components: {
      fileUpload,
      editPic,
      inputCom,
      PcDialog
    },
    data() {
      return {
        formData: [],
        quoterData: [],
        payData: [],
        imageFiles: [],
        remarkClose: '',
        demandId: this.id,
        isClose: this.isCloseOper
      };
    },
    created() {
      this.initData();
    },
    computed: {
    },
    methods: {
      getInputOwnerVal(val) {
        this.remarkClose = val;
      },
      getFileUrls(titleImg, fileNameArr, fileUrlArr) {
        // 处理新添加的图片
        for (let i = 0; i < fileUrlArr.length; i++) {
          let hit = false;
          for (let j = 0; j < this.imageFiles.length; j++) {
            if (fileUrlArr[i] === this.imageFiles[j].url) {
              hit = true;
            }
          }
          if (hit === false) {
            let singleImg = {id: null, name: '', url: ''};
            singleImg.name = fileNameArr[i];
            singleImg.url = fileUrlArr[i];
            this.imageFiles.push(singleImg);
          }
        }
        // 处理被删除的图片
        let imageFilesTmp = this.imageFiles;
        this.imageFiles = [];
        for (let j = 0; j < imageFilesTmp.length; j++) {
          for (let i = 0; i < fileUrlArr.length; i++) {
            if (fileUrlArr[i] === imageFilesTmp[j].url) {
              this.imageFiles.push(imageFilesTmp[j]);
            }
          }
        }
      },
      // 根据求购ID获取求购的详细数据
      initData() {
        this.ajax({
          url: '/ibs/web/demand/detail/' + this.demandId,
          type: 'GET',
          success: (res) => {
            setTimeout(() => {
              this.$pcNProgress.done();
            }, 300);
            this.formData = res.result;
            this.quoterData = res.result.demandDetailQuoteVos;
            this.payData = res.result.demandInfoPayVos;
            if (res.result.demandFileVos !== null) {
              this.formData.demandFileVos.forEach((item, index) => {
                let singleImg = {id: null, name: '', url: ''};
                singleImg.id = item.id;
                singleImg.name = item.name;
                singleImg.url = item.url;
                this.imageFiles.push(singleImg);
              });
            }
            this.remarkClose = res.result.remarkClose;
            this.$previewRefresh();
          }
        });
      },
      updateCredential() {
        // 检查交易凭证的个数
        if (this.imageFiles.length === 0) {
          this.errorTip('请上传交易凭证！');
          return;
        }

        // 将被选择的对象加入到后端接口参数中
        var fileDtoList = [];
        this.imageFiles.forEach(function(item) {
          fileDtoList.push({id: item.id, name: item.name, url: item.url});
        });

        var that = this;
        // 调用后端接口
        this.ajax({
          type: 'POST',
          url: '/ibs/web/demand/updateCredential',
          data: {actionDto: {demandId: that.formData.id, version: that.formData.version}, close: that.isClose, fileDtoList: fileDtoList, remarkClose: that.remarkClose},
          loading: true,
          success: (res) => {
            setTimeout(() => {
              this.$pcNProgress.done();
            }, 300);
            if (res.code === 200) {
              if (that.isCloseOper) {
                this.successTip('关闭求购成功', 2000);
              } else {
                this.successTip('更新成功', 2000);
              }
              that.$emit('sure');
            } else {
              this.errorTip(res.message);
            }
          }
        });
      }
    }
  };
</script>
<style>
  .page-demand-detail {
    width: 958px;
  }
  .page-demand-detail .table{
    display:table;
    border-collapse:collapse;
    border:1px solid #e5e5e5;
    width:100%;
    background:#ffffff;
  }
  .page-demand-detail .table .table-row-group{
    display:table-row-group;
    width: 100%;
    border-top: 1px solid #e5e5e5;
    border-left:1px solid #e5e5e5;
  }
  .page-demand-detail .table .table-row-group .table-row{
    display:table-row;
    height: 40px;
  }
  .page-demand-detail .table .table-row-group .table-row .table-cell-title{
    display:table-cell;
    padding:0 5px;
    border-left:1px solid #e5e5e5;
    border-right:1px solid #e5e5e5;
    height: 40px;
    width: 160px;
    line-height: 40px;
    text-align:center;
    color: #4d4d4d;
  }
  .page-demand-detail .table .table-row-group .table-row .table-cell-content{
    display:table-cell;
    padding:0 5px;
    border-left:1px solid #e5e5e5;
    border-right:1px solid #e5e5e5;
    height: 40px;
    width: 320px;
    line-height: 40px;
    text-indent: 20px;
    color: #1a1a1a;
  }
  .page-demand-detail .table .table-row-group .table-row .table-cell-title-lastrow{
    display:table-cell;
    padding:0 5px;
    border-left:1px solid #e5e5e5;
    border-right:1px solid #e5e5e5;
    height: 40px;
    width: 160px;
    line-height: 40px;
    text-align:center;
    color: #4d4d4d;
  }
  .page-demand-detail .table .table-row-group .table-row .table-cell-content-lastrow{
    display:table-cell;
    padding:0 5px;
    border-left:1px solid #e5e5e5;
    border-right:1px solid #e5e5e5;
    height: 40px;
    width: 800px;
    line-height: 40px;
    text-indent: 20px;
    color: #1a1a1a;
  }
  .page-demand-detail .el-table--border td{
    border-right:1px solid #e5e5e5;
    border-bottom: 1px solid #e5e5e5;
  }
  .page-demand-detail .table .w50 ul{
    box-sizing: border-box;
  }
  .page-demand-detail .el-table--border td div{
    color:#000;
  }
  .br0{
    border-right:none;
  }
  .page-demand-detail .mb-1{
    margin-top:-1px;
    margin-bottom:-1px;
  }
  .page-demand-detail .table-title{
    font-size:16px;
    color:#333333;
    border:1px solid #ebeef5;
    background:#fff;
    height: 50px;
    line-height:50px;
    padding-left:20px;
    margin-top:26px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    margin-bottom:-1px;
  }
  .page-demand-detail .table-content{
    font-size:16px;
    color:#333333;
    border:1px solid #ebeef5;
    background:#fff;
    border-spacing: 0;
    border-collapse:separate;
  }
  .remarkFrameClass
  {
    width: 100%;
    height: 170px;
    margin-top: 30px;
    background-color: white;
    border: 1px solid #e4e4e4;
  }
  .remarkFrameClass .remarkTitleClass
  {
    margin-left: 20px;
    margin-top: 20px;
    font-size: 14px;
    color: #333333;
  }
  .remarkFrameClass .remarkContentClass
  {
    margin-top: 20px;
    margin-left: 20px;
    height: 60px;
    width: 95.5%;
    background-color: white;
  }
  .btnFrameClass
  {
    margin-left: 350px;
    margin-top: 30px;
    margin-bottom: 30px;
  }
  .singleBtnClass
  {
    width: 140px;
    height: 40px;
  }

</style>
